package com.carleasoft.mps.security.permission.data;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program:
 * @description:
 * @author: ztm
 * @create: 2019/11/22 21:37
 **/
@Slf4j
public class ThreadSessionContext {

    static final ThreadLocal<List<RequiresDataPermission.Scope>> current = new ThreadLocal<>();

    public ThreadSessionContext(List<RequiresDataPermission.Scope> method) {
        current.set(method);
    }

    public static List<RequiresDataPermission.Scope> getCurrentMethods() {
        return current.get();
    }

    public static void close() {
        current.remove();
    }

    public static void setDataPermissionMethods(RequiresDataPermission.Scope method) {
        List<RequiresDataPermission.Scope> methods=current.get();
        if (methods==null) methods= Collections.synchronizedList(new ArrayList<>());
        methods.add(method);
        current.set(methods);
    }

}
